package com.mall.controller;

import com.domain.Card;
import com.domain.DishTradePayment;
import com.domain.RechSubsidy;
import com.domain.result.ResultData;
import com.github.pagehelper.PageHelper;
import com.service.seinterface.CardBatchRechDetailsService;
import com.service.seinterface.CardService;
import com.service.seinterface.DishTradePaymentService;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RequestMapping("/mall")
@RestController
@CrossOrigin
public class DishController {


    @Resource
    CardService cardService;

    @Resource
    CardBatchRechDetailsService cardBatchRechDetailsService;

    @Resource
    DishTradePaymentService dishTradePaymentService;






    /**
     * 获取充值记录分页
     *
     * @param no        身份证号码
     * @param pageNo    页数
     * @param pageCount 每页条目
     * @return
     */
    @RequestMapping("/getrechargelist")
    public ResultData getRechargeInfoList(String no,String card,@RequestParam(required = false) Integer pageNo, @RequestParam(required = false) Integer pageCount) {
        if (pageNo != null && pageCount != null) {
            PageHelper.startPage(pageNo, pageCount);
        }
        ResultData resultData = new ResultData();
        List<RechSubsidy> cards = cardBatchRechDetailsService.selectByCardNo(no,card);
        resultData.setData(cards);
        return resultData;
    }


    /**
     * @param no 身份证号码
     * @return
     */
    @RequestMapping("/getcardinfo")
    public ResultData getCardInfo(String no) {
        ResultData resultData = new ResultData();
        List<Card> cards = cardService.selectByCardNo(no);
        resultData.setData(cards);
        return resultData;
    }

    /**
     * 消费记录
     * @param uid (cardid+","+cardno)
     * @param pageNo
     * @param pageCount
     * @return
     */
    @RequestMapping("/getpaylist")
    public ResultData getPayList(String uid, @RequestParam(required = false) Integer pageNo, @RequestParam(required = false) Integer pageCount){
        if (pageNo != null && pageCount != null) {
            PageHelper.startPage(pageNo, pageCount);
        }
        ResultData resultData = new ResultData();
        List<DishTradePayment> cards = dishTradePaymentService.selectAllByuid(uid);
        resultData.setData(cards);
        return resultData;
    }




}
